#! /bin/bash
HIVE_HOME=/usr/bin/hive


${HIVE_HOME} -S -e "
use oe_dwb;

-- 班级人数表
insert into table dwb_class_studying_student_count
select *
from oe_dwd.dwd_dim_class_studying_student_count;

-- 打卡宽表
insert into table dwb_check_detail
select ssr.id,
       ssr.time_table_id,
       ssr.class_id,
       ssr.student_id,
       ssr.signin_time,
       ssr.signin_date,
       ssr.share_state,
       ctud.class_date,
       ctud.content,
       ctt.morning_template_id,
       ctt.morning_begin_time,
       ctt.morning_end_time,
       ctt.afternoon_template_id,
       ctt.afternoon_begin_time,
       ctt.afternoon_end_time,
       ctt.evening_template_id,
       ctt.evening_begin_time,
       ctt.evening_end_time,
       ctt.use_begin_date,
       ctt.use_end_date
from oe_dwd.dwd_fact_student_signin_record ssr
         left join oe_dwd.dwd_dim_class_time_table ctt on ssr.class_id = ctt.class_id
         left join oe_dwd.dwd_dim_course_table_upload_detail ctud
                   on ssr.class_id = ctud.class_id and class_date = signin_date;

-- 请假宽表
insert into table dwb_leave_detail
select sla.id,
       sla.class_id,
       sla.student_id,
       sla.audit_state,
       sla.begin_time,
       sla.begin_time_type,
       sla.end_time,
       sla.end_time_type,
       sla.cancel_state,
       sla.valid_state,
       ctud.class_date,
       ctud.content,
       ctt.morning_template_id,
       ctt.morning_begin_time,
       ctt.morning_end_time,
       ctt.afternoon_template_id,
       ctt.afternoon_begin_time,
       ctt.afternoon_end_time,
       ctt.evening_template_id,
       ctt.evening_begin_time,
       ctt.evening_end_time,
       ctt.use_begin_date,
       ctt.use_end_date
from oe_dwd.dwd_fact_student_leave_apply sla
         left join oe_dwd.dwd_dim_class_time_table ctt on sla.class_id = ctt.class_id
         left join oe_dwd.dwd_dim_course_table_upload_detail ctud
                   on sla.class_id = ctud.class_id;"